package com.playball.lottery.util;

import java.net.URLEncoder;

import android.util.Log;

/***
 * 
* @ClassName: ShenzhoufuUtil 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author vanszhen 
* @date 2014年8月22日 下午2:40:58 
*
 */
public class ShenzhoufuUtil {
	
	/**神州行充值卡服务器直连接口入口*/
    String szfurl = "http://pay3.shenzhoufu.com/interface/version3/serverconnszx/entry-noxml.aspx";   
	
	/**服务器返回地址*/
	private String  returnUrl = "http://www.jiangduoduo.com/action/site/pay/shenzhoufunotice.ashx" ;
	/**接口版本号*/
	private    String version = "3"; 
	/**商户 ID*/
	private  String merId = "174291";  
	
	/**用户名           可不要*/
	private   String merUserName = "";  
	/**用户 Email             可不要*/
	//private   String merUserMail = "";  
	
	/**商户私有数据*/
	private    String privateField = "jddgcj";  
	/**数据校验方式*/
	private    String verifyType = "1";//MD5 校验
	/**des密钥*/
	private   String desKey = "Rd+RNCoHYg4=";
	
	/**privateKey*/
	private   String privateKey = "BA9E0F066A0F4746925F3952A419E013";
	
	/**0：移动 1：联通 2：电信*/
	private    String cardTypeCombine = "0"; 
	/**订单金额	单位：分*/
	private String payMoney = "0" ;
	/**订单号*/
	private String orderId ; // 108接口 得到
	
	////////////////////////////////页面传过来
	/**充值卡面值*/
	private String cardMoney = "20" ;
	/**充值卡序列号*/
	private String sn = ""; 
	/**充值卡密码*/
	private String password = ""; 
	
	
	
	public ShenzhoufuUtil() {
		super();
		// TODO Auto-generated constructor stub
	}


	/***
	 * 
	* <p>Title: </p> 
	* <p>Description: </p> 
	* @param orderId
	* @param cardTypeCombine
	* @param merUserName
	* @param cardMoney
	* @param sn
	* @param password
	 */
	public ShenzhoufuUtil(String orderId ,  String cardTypeCombine ,String merUserName, String cardMoney, String sn, String password) {
		super();
		this.orderId = orderId ;
		this.cardTypeCombine = cardTypeCombine ;
		this.merUserName = merUserName;
		this.cardMoney = cardMoney;
		this.sn = sn;
		this.password = password;
	}


	/**拼接 参数*/
	public String urlRequestData(String orderId ,  String cardTypeCombine ,String merUserName, String cardMoney, String sn, String password) {
		  String urlRequestData ="";
		try {
		      String cardInfo = ServerConnSzxUtils.getDesEncryptBase64String(cardMoney, sn, password, desKey);   //充值卡加密信息
			  String combineString = version + merId + payMoney + orderId + returnUrl + cardInfo + privateField + verifyType + privateKey;
			//  Log.d("van", "md5加密前拼窜：" + combineString);
			  String md5String = MD5Encrypt.md5Encryption(combineString); //md5加密串 32位
			  urlRequestData = szfurl + "?version=" + version
			            + "&merId=" + merId
			            + "&payMoney=" + payMoney
			            + "&orderId=" + orderId
			            + "&returnUrl=" + returnUrl
			            + "&cardInfo=" + URLEncoder.encode(cardInfo, "utf-8")
			            + "&merUserName=" + merUserName
			           // + "&merUserMail=" + merUserMail
			            + "&privateField=" + privateField
			            + "&verifyType=" + verifyType
			            + "&cardTypeCombine=" + cardTypeCombine
			            + "&md5String=" + md5String ;
			           // + "&signString=";
			//  Log.d("van", "urlRequestData ：" + urlRequestData);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return urlRequestData;
	}
	
	/**卡号 长度 判断 哪种卡*/
	public String  getCardTypeCombine(String cradNum) {
		String cardTypeCombine = "" ;
		int len =  cradNum.length() ;
		//移动
		if (len == 16 || len == 17 || len == 10 ) {
			cardTypeCombine = "0" ;
		}
		//电信
		else if (len == 19 ) {
			cardTypeCombine = "2" ;
		}
		//联通
		else if (len == 15 ) {
			cardTypeCombine = "1" ;
		}
		return cardTypeCombine ;
	}
	

	/**返回的code 提示*/
	public  String  codeShowTip(String code ){
		String showTipStr = "";
		if (code.equals("0")) {
			showTipStr = "网络连接失败" ;
		}else if (code.equals("101")) {
			showTipStr = "md5验证失败" ;
		}else if (code.equals("102")) {
			showTipStr = "订单号重复" ;
		}else if (code.equals("103")) {
			showTipStr = "恶意用户" ;
		}else if (code.equals("104")) {
			showTipStr = "卡号或密码简单验证失败" ;
		}else if (code.equals("105")) {
			showTipStr = "密码正在处理中" ;
		}else if (code.equals("106")) {
			showTipStr = "系统繁忙，暂停提交" ;
		}else if (code.equals("107")) {
			showTipStr = "卡内余额不足" ;
		}else if (code.equals("109")) {
			showTipStr = "des解密失败" ;
		}else if (code.equals("200")) {
			showTipStr = "密码正在处理中" ;
		}else if (code.equals("201")) {
			showTipStr = "证书验证失败" ;
		}else if (code.equals("299")) {
			showTipStr = "系统忙，请重试" ;
		}else if (code.equals("501")) {
			showTipStr = "插入数据库失败" ;
		}else if (code.equals("502")) {
			showTipStr = "插入数据库失败" ;
		}else if (code.equals("902")) {
			showTipStr = "商户参数不全" ;
		}else if (code.equals("903")) {
			showTipStr = "商户 ID 不存在" ;
		}else if (code.equals("904")) {
			showTipStr = "商户没有激活" ;
		}else if (code.equals("905")) {
			showTipStr = "商户没有使用该接口的权限" ;
		}else if (code.equals("906")) {
			showTipStr = "商户没有设置privateKey密钥" ;
		}else if (code.equals("907")) {
			showTipStr = "商户没有设置DES密钥" ;
		}else if (code.equals("908")) {
			showTipStr = "该笔订单已经处理完成" ;
		}else if (code.equals("910")) {
			showTipStr = "服务器返回地址，不符合规范" ;
		}else if (code.equals("911")) {
			showTipStr = "订单号，不符合规范" ;
		}else if (code.equals("912")) {
			showTipStr = "非法订单" ;
		}else if (code.equals("913")) {
			showTipStr = "该地方卡暂时不支持" ;
		}else if (code.equals("914")) {
			showTipStr = "金额非法" ;
		}else if (code.equals("915")) {
			showTipStr = "卡面额非法" ;
		}else if (code.equals("916")) {
			showTipStr = "商户不支持该充值卡" ;
		}else if (code.equals("917")) {
			showTipStr = "参数格式不正确" ;
		}
		return showTipStr;
	}


}
